<template>
  <div class="user-info">
    <el-dropdown class="user-content" :hide-on-click="false">
      <span class="el-dropdown-link">
        <img src="~assets/image/monkey.png" />
        <span class="user-name">小猿</span>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="handleLogoutClick">
            <el-icon><CircleCloseFilled /></el-icon>退出登录
          </el-dropdown-item>
          <el-dropdown-item divided>
            <el-icon><UserFilled /></el-icon>用户系统
          </el-dropdown-item>
          <el-dropdown-item divided>
            <el-icon><Tools /></el-icon>系统管理
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { CircleCloseFilled, UserFilled, Tools } from '@element-plus/icons-vue'
import { useStore } from '@/store'
import localCache from '@/utils/cache'
import { useRouter } from 'vue-router'

export default defineComponent({
  components: {
    CircleCloseFilled,
    UserFilled,
    Tools
  },
  setup() {
    const store = useStore()
    const userName = computed(() => store.state.login.userInfo.name)

    const router = useRouter()
    const handleLogoutClick = () => {
      localCache.removeCache('token')
      router.push('/')
    }

    return {
      userName,
      handleLogoutClick
    }
  }
})
</script>

<style scoped lang="less">
.user-info {
  cursor: pointer;
  .user-content {
    .el-dropdown-link {
      display: flex;
      align-items: center;
      img {
        width: 50px;
        height: 50px;
      }
      .user-name {
        margin-left: 5px;
      }
    }
  }
}
</style>
